package reveal

import (
	"fmt"
	"net"

	"github.com/google/gopacket"
	"github.com/google/gopacket/layers"
)

// 解包、揭露
func Reveal() {
	var (
		payload   = []byte{65, 66, 67}
		options   = gopacket.SerializeOptions{}
		buffer    = gopacket.NewSerializeBuffer()
		raw       []byte
		srcMac, _ = net.ParseMAC("68:07:15:42:29:1c")
		dstMac, _ = net.ParseMAC("1C:77:F6:88:68:F0")
	)
	gopacket.SerializeLayers(buffer, options,
		&layers.Ethernet{SrcMAC: srcMac, DstMAC: dstMac},
		&layers.IPv4{SrcIP: net.IP{192, 168, 2, 37}, DstIP: net.IP{192, 168, 2, 26}},
		&layers.TCP{SrcPort: 81, DstPort: 11111}, gopacket.Payload(payload))
	raw = buffer.Bytes()
	//解析链路层数据
	ethPacket := gopacket.NewPacket(raw, layers.LayerTypeEthernet, gopacket.Default)
	//解析网络层数据
	ipPacket := gopacket.NewPacket(raw, layers.LayerTypeIPv4, gopacket.Lazy)
	//解析传输层数据
	tcpPacket := gopacket.NewPacket(raw, layers.LayerTypeTCP, gopacket.NoCopy)

	fmt.Println(ethPacket)
	fmt.Println(ipPacket)
	fmt.Println(tcpPacket)
}
